package com.hyjx.framework.common;

import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Properties;
/**
 * 属性对象工具类，可用于读取配置文件
 * @author dijian
 *
 */
public class PropertyUtil{
	private static Properties localProp = new OrderedProperties();
	private static Properties globalProp = new OrderedProperties();
	
	static {
		loadGlobal();
		loadLocal();
	}
	
	/**
	 * 返回属性信息对象
	 * @return
	 */
	public static Properties getGlobalObj(){
		return globalProp;
	}
	
	public static void loadGlobal()
	{
		try{
			InputStream is = PropertyUtil.class.getResourceAsStream("/config/global.properties");
			globalProp.clear();
			globalProp.load(is);
		}catch(Exception e){
			e.printStackTrace();
		}
	}

	public static void loadLocal()
	{
		try{
			InputStream is = (InputStream) PropertyUtil.class.getResourceAsStream("/config/local.properties");
			localProp.clear();
			localProp.load(is);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	/**
	 * 取配置信息
	 * @param key
	 * @return
	 */
	public static String getValue(String key){
		String value = (String)localProp.get(key);
		if(value != null){
			value = value.trim();
			try {
				value = new String(value.getBytes("iso8859-1"),"utf-8");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}
		return value;
	}
}